using System;
using System.Collections.Generic;
using System.Text;
using SP.Parameter;

namespace SP.HwDeferredRS
{
    /// <summary>
    /// A fusion which flips the vertex-tangent according to the vertex color
    /// </summary>
    public class UVScrollingFusion : AbstractFusion
    {
        public UVScrollingFusion()
        {
            AddParameter(new Vec2Parameter("uv1ScrollSpeed").SetDesc("Scroll Speed (U & V) of UV channel 1.\nValue [0.0-1.0]."));
            AddParameter(new Vec2Parameter("uv2ScrollSpeed").SetDesc("Scroll Speed (U & V) of UV channel 2.\nValue [0.0-1.0]."));
            AddParameter(new Vec2Parameter("uv3ScrollSpeed").SetDesc("Scroll Speed (U & V) of UV channel 3.\nValue [0.0-1.0]."));
            AddPreprocessor(new Preprocessor("UV_SCALING", 0, 1, 0, "1 to support application controlled uv scaling"));
        }

        public override string Name
        {
            get { return "UVScrolling"; }
        }

        public override string Desc
        {
            get { return "UV scrolling & scaling effect of UV channel 1-3.\nDo NOT use this with SpriteMap or BillboardScaling!"; }
        }

        public override Stage Stage
        {
            get { return Stage.Vertex0; }
        }

        public override int UVChannelCount
        {
            get { return 3; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "pipeline.UV0 += cTime * uv1ScrollSpeed + cCustom1.xy;");
            AddLine(b, "pipeline.UV1 += cTime * uv2ScrollSpeed + cCustom2.xy;");
            AddLine(b, "pipeline.UV2 += cTime * uv3ScrollSpeed + cCustom3.xy;");

            AddLine(b, "#if UV_SCALING");
            AddLine(b, "pipeline.UV0 *= cCustom1.zw;");
            AddLine(b, "pipeline.UV1 *= cCustom2.zw;");
            AddLine(b, "pipeline.UV2 *= cCustom3.zw;");
            AddLine(b, "#endif // UV_SCALING");

        }
    }
}
